import {
  Inject,
  Controller,
  Post,
  Put,
  Del,
  Get,
  Param,
  Body,
  Queries
} from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { Utils } from "../utils/index";
import { CaseService } from "../service/case.service";
import { CaseCreateDto, CasePageQueryDto } from "../dto/case.dto";

@Controller()
export class CaseController {
  @Inject()
  ctx: Context;

  @Inject()
  caseService: CaseService;

  @Inject()
  utils: Utils;

  @Post("/auth-api/case", { summary: "添加案例" })
  async add_case(@Body() dto: CaseCreateDto) {
    const result = await this.caseService.add_case(dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Put("/auth-api/case/:caseId", { summary: "更新球杆" })
  async update_case(
    @Param("caseId") caseId: string,
    @Body() dto: CaseCreateDto
  ) {
    const result = await this.caseService.update_case(caseId, dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Del("/auth-api/case/:caseId", { summary: "删除球杆" })
  async delete_case(@Param("caseId") caseId: string) {
    const result = await this.caseService.delete_case(caseId);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/case/:caseId", { summary: "获取案例信息" })
  async get_case_wxapp(@Param("caseId") caseId: string) {
    const result = await this.caseService.get_case(caseId);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/case/list", { summary: "获取球杆列表" })
  async get_case_list() {
    const result = await this.caseService.get_case_list();
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/case/page", { summary: "获取球杆分页列表" })
  async get_case_page_list(@Queries() dto: CasePageQueryDto) {
    const result = await this.caseService.get_case_page_list(dto);
    return this.utils.response.success({
      ...result
    });
  }
}
